package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.dto.role.RoleDTO;
import com.qk.entity.Role;
import com.qk.management.aop.anno.LogAnno;
import com.qk.management.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author:Shuna
 * @Date: 2025/10/08 19:43
 * @Description:
 */
@RestController
@RequestMapping("/roles")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @GetMapping
    public Result list(RoleDTO roleDTO){
        PageResult<Role> pageResult = roleService.list(roleDTO);
        return Result.success(pageResult);
    }

    @LogAnno
    @PostMapping
    public Result add(@RequestBody Role role){
        roleService.add(role);
        return Result.success();
    }

    @LogAnno
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        roleService.deleteById(id);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        Role role = roleService.getById(id);
        return Result.success(role);
    }

    @LogAnno
    @PutMapping
    public Result update(@RequestBody Role role){
        roleService.update(role);
        return Result.success();
    }

    @GetMapping("/list")
    public Result getAll(){
        List<Role> roles = roleService.getAll();
        return Result.success(roles);
    }

}
